
#ifndef __SYSTASK_H
#define	__SYSTASK_H

#include <stdint.h>
#include "dataproc.h"
#include "pulse.h"
#include "rtctime.h"
#include "mytype.h"
#include "iohandle.h"
#include "simp_log.h"
#include "sw_pwm.h"

#ifdef	__cplusplus
extern "C" {
#endif
	
#ifdef   _SYSTASK_MODULE_
#define  MY_EXT
#else
#define  MY_EXT  extern
#endif  

typedef struct
{
    int16_t lgt;
    int16_t time;
} prog_tab_type;

typedef struct 
{
    volatile uint32_t u_tick;
    volatile uint32_t powerup_time_cnt;
    uint32_t app_timer_err;
    
		struct 
	{
		volatile uint8_t sem_req;
		volatile uint32_t sem_send_tick;
		volatile uint32_t sem_rcv_tick;
		volatile uint32_t sem_tick_amount;
		
		volatile uint8_t event_req;
		volatile uint32_t event_send_tick;
		uint32_t event_rcv_tick;
		uint32_t event_tick_amount;
		uint32_t event_dat;
		
		volatile uint8_t quene_req;
		volatile uint32_t quene_send_tick;
		volatile uint32_t quene_rcv_tick;
		volatile uint32_t quene_tick_amount;
		uint32_t quene_dat[4];
			
		volatile uint8_t mutex_req;
		uint32_t mutex_req_tick;
		uint32_t mutex_put_tick;
		uint32_t mutex_get_tick;
		uint32_t mutex_get_tick_amount;
		uint32_t mutex_put_tick_amount;
		volatile uint8_t b_mutex_busy;
		
		
	} api_tick;
	
    timer_pulse_type pulse;
    sig_time_type sig_time;
    TIME_Type rtc_time;
    
    uint16_t duty;
    uint8_t pwm_tick_cnt;
    uint8_t duty_cal_list[102];
    uint8_t duty_out_list[102];
    sim_pwms_type tpwms;
    
    int32_t itostr;
    uint8_t ipn,ipattr;
    
    char ch_req;
    int16_t site;
    char str_buff[128];
    char str_res[128];
    int16_t site_list[8];
    char password_asc[20];
    uint16_t elec_val;
    uint16_t elec_period;
    uint8_t elec_list[128];
    UINT32_VAL password_num;
    
    prog_tab_type prog_tab[10];
    int8_t seg_next, seg_fore, seg_max, seg_act, seg_num;
    
    discont_in_flt_type disflt;
    int16_t i_air_temp;
    
    int8_t log_mode;
    simp_log_info_type log_info;
    sig_time_type log_s_val;
    uint32_t log_r_site;
    uint32_t log_w_req;
    uint32_t log_s_req;
    uint32_t log_r_req;
    
    uint32_t log_w[16];
    uint32_t log_r[16];
	
	long alain_src;
	long alsin_out;
} sys_run_st_type;

MY_EXT sys_run_st_type sys_st;

int8_t prog_seg_max(prog_tab_type *tab);
int8_t prog_seg_amount(prog_tab_type *tab);
int8_t prog_seg_effective(prog_tab_type *tab);
int8_t prog_seg_next(prog_tab_type *tab, int8_t seg_now);
int8_t prog_seg_fore(prog_tab_type *tab, int8_t seg_now);

#undef MY_EXT

#ifdef	__cplusplus
}
#endif

#endif	/* __SYSTASK_H */
